package dk.dashboardFP.panels.displayPanel {
	import dk.dashboardFP.elements.button.ButtonElement;
	import dk.dashboardFP.interactionElementFramwork.buttons.AbstractButton;
	import dk.dashboardFP.interactionElementFramwork.buttons.ButtonEvent;
	import dk.dashboardFP.panels.displayPanel.tools.ToggleButtonGroup;

	/**
	 * @author josef
	 */
	public class ToolsButtonGroup extends ToggleButtonGroup {

		private var _oDisplayPanel : DisplayPanel;

		public function ToolsButtonGroup(oDisplayPanel : DisplayPanel) {
			
			_oDisplayPanel = oDisplayPanel;
			super("Tools");
		}

		override protected function setupElements() : void {	
			super.setupElements();
			
			//:::::::
			// create buttons 
			addElement(new ButtonElement(DisplayEditorModes.SELECT, "select", ""));
			addElement(new ButtonElement(DisplayEditorModes.MOVE, "move", ""));
			addElement(new ButtonElement(DisplayEditorModes.PAN, "pan", ""));
		}

		private function onModeChanged(event : DisplayEditorControlEvent) : void {
			if (_oDisplayPanel.oDisplayEditorControl.bEnabled) {
				selectById(_oDisplayPanel.oDisplayEditorControl.sCurrentDisplayEditorMode);
			} else {
				disableGroup();
			}
		}

		override protected function onButtonClicked(event : ButtonEvent) : void {
			_oDisplayPanel.oDisplayEditorControl.setMode(AbstractButton(event.target).oRefrenceObject as String);
		}
		
		public function registerControls() : void {
			
			//:::::::
			// register controller 
			_oDisplayPanel.oDisplayEditorControl.addEventListener(DisplayEditorControlEvent.CHANGED_MODE, onModeChanged, false, 0, true);
			_oDisplayPanel.oDisplayEditorControl.addEventListener(DisplayEditorControlEvent.TOGGLE_ENABLED, onToggle, false, 0, true);
			
			onModeChanged(null);
		};

		private function onToggle(event : DisplayEditorControlEvent) : void {
			if (_oDisplayPanel.oDisplayEditorControl.bEnabled) {
				enableGroup();
				onModeChanged(null);
			} else {
				disableGroup();
			}
		}
	}
}
